<?php

// Acceso restringido
defined('JL') or die('Acceso restringido');

class MembresAdminModel extends JLModelBase {

    /**
     * Funcion que retorna Membres
     * @Retorna array
     */
    public function getMembresByIdSectionsView($id) {
        $_true = null;

        $sql = "SELECT 
              `int_id_membres_admin`,
              `var_photo`,
              `var_noms`,
              `var_status`,
              `var_dates`,
              `int_mem_order`
            FROM 
              `tbl_membres_admin`
            WHERE `int_id_administration` = " . $this->DB->Quote($id) . "
            ORDER BY `int_mem_order` ASC ";

        $this->DB->executeQuery($sql);

        if ($this->DB->getRowsAffected() > 0) {
            $_true = $this->DB->getDataArray();
        }

        return $_true;
    }

    /**
     * Funcion que retorna Membres
     * @Retorna array
     */
    public function getMembresById($id) {
        $_true = null;

        $sql = "SELECT 
              `int_id_membres_admin`,
              `var_photo`,
              `txt_photo_html`,
              `var_noms`,
              `var_status`,
              `var_dates`,
              `int_mem_order`,
              `int_id_administration`,
              `int_id_state`
            FROM 
              `tbl_membres_admin` 
            WHERE `int_id_membres_admin` = " . $this->DB->Quote($id) . "";

        $this->DB->executeQuery($sql);

        if ($this->DB->getRowsAffected() > 0) {
            $_true = $this->DB->getDataArray();
            $_true = $_true[0];
        }

        return $_true;
    }

    /**
     * Actualiza Membre Order
     * @Retorna bool
     */
    public function updateMembreOrder($id, $int_mem_order) {
        $_true = false;

        $sql = "UPDATE 
              `tbl_membres_admin`  
            SET
              `int_mem_order`   = " . $this->DB->Quote($int_mem_order) . "
            WHERE 
              `int_id_membres_admin`   = " . $this->DB->Quote($id) . " ";

        $this->DB->executeQuery($sql);

        if ($this->DB->getRowsAffected() > 0) {
            $_true = true;
        }

        return $_true;
    }

    /**
     * Actualiza Membre Order
     * @Retorna bool
     */
    public function updateMembre($id, $var_photo, $txt_photo_html, $var_noms, $var_status, $var_dates, $int_id_administration, $int_id_state) {
        $_true = false;

        $sql = "UPDATE 
              `tbl_membres_admin`  
            SET
              `var_photo` = " . $this->DB->Quote($var_photo) . ",
              `txt_photo_html` = " . $this->DB->Quote($txt_photo_html) . ",
              `var_noms` = " . $this->DB->Quote($var_noms) . ",
              `var_status` = " . $this->DB->Quote($var_status) . ",
              `var_dates` = " . $this->DB->Quote($var_dates) . ",
              `int_id_administration` = " . $this->DB->Quote($int_id_administration) . ",
              `int_id_state` = " . $this->DB->Quote($int_id_state) . "
            WHERE `int_id_membres_admin` = " . $this->DB->Quote($id) . "";

        $this->DB->executeQuery($sql);

        if ($this->DB->getRowsAffected() > 0) {
            $_true = true;
        }

        return $_true;
    }

    /**
     * Actualiza Membre Order
     * @Retorna bool
     */
    public function insertMembre($var_photo, $txt_photo_html, $var_noms, $var_status, $var_dates, $int_mem_order, $int_id_administration, $int_id_state) {
        $_true = false;

        $sql = "INSERT INTO 
              `tbl_membres_admin`
            (
              `var_photo`,
              `txt_photo_html`,
              `var_noms`,
              `var_status`,
              `var_dates`,
              `int_mem_order`,
              `int_id_administration`,
              `int_id_state`
            ) 
            VALUE (
              " . $this->DB->Quote($var_photo) . ",
              " . $this->DB->Quote($txt_photo_html) . ",
              " . $this->DB->Quote($var_noms) . ",
              " . $this->DB->Quote($var_status) . ",
              " . $this->DB->Quote($var_dates) . ",
              " . $this->DB->Quote($int_mem_order) . ",
              " . $this->DB->Quote($int_id_administration) . ",
              " . $this->DB->Quote($int_id_state) . "
            )";

        $this->DB->executeQuery($sql);

        if ($this->DB->getRowsAffected() > 0) {
            $_true = true;
        }

        return $_true;
    }

    /**
     * Elimina Membre
     * @Retorna bool
     */
    public function deleteMembre($id) {
        $_true = false;

        $sql = "DELETE FROM 
              `tbl_membres_admin` 
            WHERE 
              `int_id_membres_admin`  = " . $this->DB->Quote($id) . " AND `int_id_state` <> 1";

        $this->DB->executeQuery($sql);

        if ($this->DB->getRowsAffected() > 0) {
            $_true = true;
        }

        return $_true;
    }

}